import Vue from 'vue'
import VueRouter from 'vue-router'
import register from '../views/register/register.vue'
import different from '../views/different/index.vue'
import Template from '../views/template/template.vue'
import course from '../views/course/course.vue'
import game from '../views/game/game.vue'
import courseware from '../views/courseware/courseware.vue'
import edit from '../views/edit/edit.vue'
import probation from '../views/probation/probation.vue'
import openCourse from '../views/openCourse/openCourse.vue'
import create from '../views/create/create.vue'
import Write from '../views/write/write.vue'
import lAL from '../views/lAI/lAl.vue'
import start from '../views/start/start.vue'


Vue.use(VueRouter)

const routes = [
  
  {
	  path:'/',
	  meta: { title: '', auth: true },
	  component: different,
	  children:[
		{
			path: '/',
			name:'课件',
			component:course,
			meta: { title: '', auth: true },
		},
		{
			path: '/game',
			name:'游戏',
			component:game,
			meta: { title: '', auth: true },
		},
		{
			path:'/probation',
			name:'使用教程',
			component:probation,
			meta: { title: '', auth: true },
		}
	  ]
  },
  {
    path: '/login',
    name: 'register',
    component: register
  },
  {
	  path:'/Template',
	  name:'Template',
	  meta: { title: '', auth: true },
	  component:Template
  },
  {
  	  path:'/edit',
  	  name:'编辑',
	  meta: { title: '', auth: true },
  	  component:edit
  },
  {
  	  path:'/openCourse',
  	  name:'开始游戏',
  	  meta: { title: '', auth: true },
  	  component: openCourse
  },
  {
  	  path:'/create',
  	  name:'创建游戏',
  	  meta: { title: '', auth: true },
  	  component: create
  },
  {
	  path:'/FillInWrite',
	  name:'填写题目信息',
	  meta:{ title:'', auth :true },
	  component: Write
  },
  {
  	  path:'/lAL',
  	  name:'来做课',
  	  meta:{ title:'', auth :true },
  	  component: lAL
  },
  {
	  path:'/start',
	  name:'开始做题',
	  meta:{ title:'' , auth:true},
	  component:start
  }
  
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta && to.meta.title) {
    document.title = to.meta.title;
  }
  // 如果是权限路由
  if (to.meta && to.meta.auth) {
    if (sessionStorage.getItem('token')) {
      next();
    } else {
      router.push("/login");
    }
  } else {
    next();
  }

})

export default router
